#!/usr/bin/perl -w 


$f_exec    = "toy_siml_submit.C";
$f_lib     = "toy_siml_submit_C";
$bin       = 25; 
$max_order = 20; # split number

&main();

sub main{

    # initialize
    &util03();

    $jobs = 0;
    $mctype = 1111;

    $jobs = $jobs + &util01( 0.5, 10, $mctype);
    $jobs = $jobs + &util01( 0.5, 20, $mctype);
    $jobs = $jobs + &util01( 0.5, 30, $mctype);
    $jobs = $jobs + &util01( 0.5, 40, $mctype);
    $jobs = $jobs + &util01( 0.5, 50, $mctype);
    $jobs = $jobs + &util01( 0.5, 60, $mctype);
    $jobs = $jobs + &util01( 0.5, 70, $mctype);
    $jobs = $jobs + &util01( 0.5, 80, $mctype);
    $jobs = $jobs + &util01( 0.5, 90, $mctype);
    $jobs = $jobs + &util01( 0.5,100, $mctype);

    $jobs = $jobs + &util01( 0.75, 10, $mctype);
    $jobs = $jobs + &util01( 0.75, 20, $mctype);
    $jobs = $jobs + &util01( 0.75, 30, $mctype);
    $jobs = $jobs + &util01( 0.75, 40, $mctype);
    $jobs = $jobs + &util01( 0.75, 50, $mctype);
    $jobs = $jobs + &util01( 0.75, 60, $mctype);
    $jobs = $jobs + &util01( 0.75, 70, $mctype);
    $jobs = $jobs + &util01( 0.75, 80, $mctype);
    $jobs = $jobs + &util01( 0.75, 90, $mctype);
    $jobs = $jobs + &util01( 0.75,100, $mctype);

    $jobs = $jobs + &util01( 0.0, 28, $mctype);
    $jobs = $jobs + &util01( 0.1, 28, $mctype);
    $jobs = $jobs + &util01( 0.2, 28, $mctype);
    $jobs = $jobs + &util01( 0.3, 28, $mctype);
    $jobs = $jobs + &util01( 0.4, 28, $mctype);
    $jobs = $jobs + &util01( 0.5, 28, $mctype);
    $jobs = $jobs + &util01( 0.6, 28, $mctype);
    $jobs = $jobs + &util01( 0.7, 28, $mctype);
    $jobs = $jobs + &util01( 0.8, 28, $mctype);
    $jobs = $jobs + &util01( 0.9, 28, $mctype);
    $jobs = $jobs + &util01( 1.0, 28, $mctype);

    printf("\n\n submitted jobs : $jobs \n\n");
    system("/home/belle/ymgoh/public/util_sys/status.pl");

  return;
}



sub util01(){

  my ( $v_fl, $v_nsig, $v_comb) = @_;

  $job = 0;
  for($i=0; $i<$max_order; $i++){
      &util02( $v_fl, $v_nsig, $v_comb, $i, $bin );
      $job = $i+1;
  }
 
  return $job;
}



sub util02{

  my (  $v_fl, $v_nsig, $v_comb, $i, $bin) = @_;

  printf("fL : $v_fl, Nsig : $v_nsig, Combination : $v_comb, Order : $i, Binning : $bin -> ");
  system("bsub -q s root -b -l -q '${f_exec}+ ($v_fl, $v_nsig, $v_comb, $i, $bin)'");
#  system("root -b -l -q '${f_exec}+ ($v_fl, $v_nsig, $v_comb, $i, $bin)'");
  system("sleep 0.5");

  return;
}

sub util03(){
    
    system("rm -f ${f_lib}.so");
    system("rm -f ${f_lib}.d");    
    system("root -b -l -q '${f_exec}++ (-1, -1, -1, -1, -1)'");    
    printf("\nwaiting 5 seconds ...\n\n");
    system("sleep 5");

    return;
}
#
#
#
#===<END>
